package com.lagou.controller;

import com.lagou.common.ResponseResult;
import com.lagou.service.CodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "/code", description = "验证码服务")
@RestController
@RequestMapping("/code")
public class CodeController {

    @Autowired
    private CodeService codeService;

    @ApiOperation(value = "⽣成验证码并发送到对应邮箱，成功true，失败false", httpMethod = "GET", produces = "application/json")
    @GetMapping(value = "/create/{email}")
    public ResponseResult<Boolean> createCode(@PathVariable String email) {
        return ResponseResult.success(codeService.createCode(email));
    }

    @ApiOperation(value = "校验验证码是否正确，0正确1错误2超时", httpMethod = "POST", produces = "application/json")
    @PostMapping(value = "/validate/{email}/{code}")
    public ResponseResult<Integer> validateCode(@PathVariable String email, @PathVariable String code) {
        return ResponseResult.success(codeService.validateCode(email, code));
    }

}
